<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<title>SSHE demo</title>
<link rel="stylesheet" href="jslib/jquery-easyui-1.4.1/themes/metro/easyui.css">
<link rel="stylesheet" href="jslib/jquery-easyui-1.4.1/themes/black/easyui.css">
 <link rel="stylesheet" href="jslib/jquery-easyui-1.4.1/themes/bootstrap/easyui.css">
<!--<link rel="stylesheet" href="jslib/jquery-easyui-1.4.1/themes/default/easyui.css"> -->
<link rel="stylesheet" href="jslib/jquery-easyui-1.4.1/themes/icon.css">
<script type="text/javascript" src="jslib/jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jslib/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="jslib/easyui_extend.js"></script>

</head>
<body class="easyui-layout" >

    <div data-options="region:'north',split:true" style="height:100px;"></div>
    <div data-options="region:'south',title:'South Title'" style="height:10px;"></div>
    <div data-options="region:'east',title:'East Title',split:true" style="width:150px;">

    </div>
    <div data-options="region:'west',title:'',split:true" style="width:200px;">
    	<div class="easyui-panel" data-options="title:'123',border:false,fit:true">
            <div id="aa" class="easyui-accordion" data-options="border:false,fit:true">
                <div title="首页菜单" data-options="iconCls:'icon-man'" style="overflow:auto;padding:10px;">
                    <ul id="index_menus" class="easyui-tree" >

                    </ul>
                </div>
                <div title="Title3">
                    content3
                </div>
            </div>
        </div>
    </div>
    <div data-options="region:'center',title:'欢迎使用sshe管理系统'" >

        <div id="index_centerTabs" class="easyui-tabs" data-options="fit:true,border:false">
            <div title="首页" style="padding:10px;" closable="true">
                首页
            </div>
        </div>
    </div>

  <jsp:include page="user/reg.jsp"></jsp:include>
  <jsp:include page="user/login.jsp"></jsp:include>

</body>

<script type="text/javascript" >
    function addTab(opts){
        var t = $("#index_centerTabs");
        if(t.tabs('exists',opts.title)){
            t.tabs('select',opts.title);
        }else{
            t.tabs('add',opts);
        }
    }

$(function(){
    $('#index_menus').tree({
        url:'${pageContext.request.contextPath}/menu/menuAction!showMenu.action',
        loadFilter: function(rows){
            var v = convert(rows);
            return v;
        },
        onLoadSuccess:function(){
           /* $(this).tree('collapseAll');*/
        },
        onClick:function(node){
            /*href只载入body内的内容*/
            if(node.attributes.url){
                //排除无url的tab
                addTab({title:node.text,href:"${pageContext.request.contextPath}"+node.attributes.url,closable:true});
            }
        }
    });
});

/**
*simpledata 数据
* @param rows
* @returns {Array}
 */
function convert(rows){
    function exists(rows, parentId){
        for(var i=0; i<rows.length; i++){
            if (rows[i].id == parentId) return true;
        }
        return false;
    }

    var nodes = [];
    // get the top level nodes
    for(var i=0; i<rows.length; i++){
        var row = rows[i];
        if (!exists(rows, $.isEmptyObject(row.pid)?"-1":row.pid)){
            nodes.push({
                id:row.id,
                text:row.text,
                attributes:row.attributes
            });
        }
    }

    var toDo = [];
    for(var i=0; i<nodes.length; i++){
        toDo.push(nodes[i]);
    }
    while(toDo.length){
        var node = toDo.shift();	// the parent node
        // get the children nodes
        for(var i=0; i<rows.length; i++){
            var row = rows[i];
            if (row.pid == node.id){
                var child = {id:row.id,text:row.text,attributes:row.attributes};
                if (node.children){
                    node.children.push(child);
                } else {
                    node.children = [child];
                }
                toDo.push(child);
            }
        }
    }
    return nodes;
}





</script>
</html>